package com.songshuai.webapi.permission.common.enumerations.error;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum DepartmentError {


    ERROR_EMAIL_AND_MOBILE_BOTH_NULL(1,"电子邮箱或手机号不可为空"),
    ERROR_EMIAL_FORMAT(2,"电子邮箱格式不正确"),
    ERROR_MOBILE_FORMAT(3,"手机号格式不正确"),
    ERROR_EMAIL_IS_EXIST(4,"电子邮箱已占用"),
    ERROR_MOBILE_IS_EXIST(5,"手机号已占用"),
    ERROR_DEPARTMENT_ID_NOT_EXIST(6,"部门不存在"),
    ERROR_DEPARTMENT_RELATION_IS_EXIST(7,"部门关系已经存在"),
    ERROR_DEPARTMENT_RELATION_IS_NOT_EXIST(8,"非该部门下用户"),
    ERROR_WORK_NO_IS_EXIST(9,"工号已占用");




    private int code;
    private String msg;

    DepartmentError(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return DepartmentError.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return DepartmentError.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(DepartmentError err : DepartmentError.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
